<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="../include/tag.jsp"%>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>${response == null ? '新建' : '编辑'}</title>
    <%@include file="../include/commonFile.jsp"%>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/ui/activity/publish_form.css">
    <style type="text/css">
        .contentedit{
            height: 210px;
            resize: none;
            border: 0;
            font-size: 14px;
            line-height: 22px;
            padding: 16px;
            outline: 0;
            word-wrap: break-word;
            overflow-x: hidden;
            overflow-y: auto;
            -webkit-user-modify: read-write-plaintext-only;
            position: relative;
            border: solid 1px #e7e7eb;
        }
    </style>
</head><body>
<!--头部-->
<%@include file="../include/header.jsp"%>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp"%>
    <!--内容-->
    <section>
        <div class="section-main">
            <!-- 正文请写在这里 -->
            <div class="add-form-content">
            <form id="myForm" class="layui-form mt20" method="post" action="${ctx}/wechat/keywordresponse/save.do">
                <input type="hidden" name="id" value="${response.id}" />
                <input type="hidden" name="type" value="3" />
                <%--目前只有文本类型--%>
                <input type="hidden" name="replyType" value="text" />
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">关键词<span class="f-verify-red">*</span></label>
                        <div class="layui-input-inline">
                            <input type="text" name="key" lay-verify="key" autocomplete="off" class="layui-input"
                                   value="${response.key}"
                            >
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">内容<span class="f-verify-red">*</span></label>
                    <div class="layui-input-block">
                        <textarea id="content" name="content" rows="15" cols="150" class="contentedit" lay-verify="content">${response.content}</textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <a href="javascript:void(0)" class="layui-btn layui-btn-danger" lay-submit lay-filter="*">立即提交</a>
						<a href="${ctx}/wechat/keywordresponse/view.do" class="layui-btn layui-btn-primary">取消</a>
                    </div>
                </div>
            </form>
            </div>
        </div><%@include file="../include/footer.jsp"%>
    </section>
</div>
<!--底部-->
<script type="text/javascript" src="${ctx}/script/common/form_cache.js"></script>

<script>

    $(function () {
        layui.use([ 'form', 'laydate' ], function() {
            var form = layui.form;

            //自定义验证规则
            form.verify({
                key : function(value) {
                    if (value == "") {
                        return '请填写关键词';
                    }
                },
                content : function(value) {
                    var content = $("#contentView").val();
                    if (content == "") {
                        return "请填写回复内容";
                    }
                }
            });

            //监听提交
            form.on('submit', function (data) {
                txz.submitObject(data.elem, function (callBack) {
                    var formData = getFormData();
                    txz.ajaxRequest({
                        method: 'post',
                        url: '${ctx}/wechat/keywordresponse/save.do',
                        params: formData,
                        callBack: function (res) {
                            typeof callBack === 'function' && callBack();
                            if (res.success) {
                                util.layerMsgSuccess("提交成功", function () {
                                    location.href = "${ctx}/wechat/keywordresponse/view.do";
                                });
                            } else {
                                util.layerMsgError("提交失败")
                            }
                        }
                    })
                });
                return false;
            });
        });

    })

    function getFormData() {
        var formData = util.serializeForm($('#myForm').serializeArray());
        return formData;
    }
</script>
<c:if test="${empty response}">
    <script type="text/javascript">
        txz.initHeader({
            nav:[{
                name: '关键词回复',
                href: '${ctx}/wechat/keywordresponse/view.do'
            },{
                name: '新建',
                curr: true
            }],
            btns:[{
                name: '返回',
                icon: 'back',
                href: '${ctx}/wechat/keywordresponse/view.do'
            }]
        });
    </script>
</c:if>
<c:if test="${not empty response}">
    <script type="text/javascript">
        txz.initHeader({
            nav:[{
                name: '关键词回复',
                href: '${ctx}/wechat/keywordresponse/view.do'
            },{
                name: '编辑',
                curr: true
            }],
            btns:[{
                name: '返回',
                icon: 'back',
                href: '${ctx}/wechat/keywordresponse/view.do'
            }]
        });
    </script>
</c:if>
</body>
</html>